package cn.pzhu.edu.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.pzhu.edu.entity.Message;
import cn.pzhu.edu.entity.User;
import cn.pzhu.edu.service.imp.UserServiceImp;
import cn.pzhu.edu.service.inf.UserService;

/**
 * Servlet implementation class DestroyUserServlet
 */
@WebServlet("/DestroyUserServlet")
public class DestroyUserServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DestroyUserServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		UserService userService = new UserServiceImp();
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		User user =new User(username,password);
		Message message = userService.delete(user);
		if(message.isRes()){
			request.getSession().setAttribute("msg", message.getMsg());
			response.sendRedirect(request.getContextPath()+"/exp5/login.jsp");
		}else{
			request.getSession().setAttribute("msg", message.getMsg());
			response.sendRedirect(request.getContextPath()+"/exp5/success.jsp");
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
